﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

namespace Projet_Final_ASP
{
    public partial class Produit : System.Web.UI.Page
    {
        public static List<oProduit> listeProduits = new List<oProduit>();
        protected void Page_Load(object sender, EventArgs e)
        {           
            if (!IsPostBack)
            {
                this.GridView1.DataSource = null;
                string command = "SELECT [NoProduit], [NomProduit], [Description], [Prix], [Image] FROM [Produits] WHERE [TypeID] = " + Request.QueryString["Type"];
                OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + HttpContext.Current.Server.MapPath("~/App_Data/FinalASP.accdb") + ";Persist Security Info=True");
                OleDbCommand oledbcmd = new OleDbCommand(command, cn);
                OleDbDataAdapter oledbda = new OleDbDataAdapter(oledbcmd);
                DataTable ds = new DataTable();
                oledbda.Fill(ds);

                this.GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }

        protected void Achat_Click(object sender, CommandEventArgs e)
        {
            GridViewRow gvr = this.GridView1.Rows[Convert.ToInt32(e.CommandName)];
            int qty = Convert.ToInt32(((DropDownList)gvr.FindControl("DropDownList")).Text);
            Cart shoppingCart = new Cart();
            oProduit produit = AccesBD.RechercherProduit(Convert.ToInt32(e.CommandArgument));
            shoppingCart = (Cart)Session.Contents["shoppingCart"];
            shoppingCart.AddtoCart(produit, qty, produit.NoProduit);
            Session.Add("ShoppingCart", shoppingCart);
        }
    }
}